﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using exMath.Common;

namespace exMath.Calculus
{
    public class Polarderivative : Derivative
    {
        public Polarderivative(MathFunction PolarFunction) : base(PolarFunction) { }

        public Polarderivative(PolarFunction PolarFunction) : base(PolarFunction.Function) { }

        protected override double _derivativeFunction(double x)
        {
            double CosAngle = Math.Cos(x);
            double SinAngle = Math.Sin(x);
            double PolarFunctionResult = this.Function(x);
            
            double numerator = (CosAngle * SinAngle) + (PolarFunctionResult * CosAngle);
            double denominator = (CosAngle * CosAngle) - (PolarFunctionResult * SinAngle);

            return numerator / denominator;
        }

        public override MathFunction DerivativeFunction
        {
            get
            {
                return _derivativeFunction;
            }
        }

        public Polarderivative GetPolarderivative(MathFunction PolarFunction)
        {
            return new Polarderivative(PolarFunction);
        }

        public Polarderivative GetPolarderivative(PolarFunction PolarFunction)
        {
            return new Polarderivative(PolarFunction.Function);
        }
    }
}
